package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.common.query.DestinationQueryObject;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/destination")
public class DestinationController {

    @Reference
    private IDestinationService destinationService;

    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") DestinationQueryObject qo, Model model) {
        model.addAttribute("pageInfo", destinationService.query(qo));
        Long parentId = qo.getParentId();

        //在这里判断parentId,如果-1,表示查询顶级
        //这里必须判断,否则查询吐司执行查询单条数据会导致查询parentId=-1空指针
        if (parentId > 0) {
            model.addAttribute("toasts", destinationService.listToast(parentId));
        }
        return "destination/list";
    }
}
